package website.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import website.advice.BaseResponse;
import website.domain.Link;
import website.domain.Message;
import website.domain.ResModel;
import website.domain.User;
import website.service.LinkService;

import java.util.List;

@Api("友链控制类")
@BaseResponse
@RestController
@RequestMapping("/api/link")
public class LinkController {

    @Autowired
    private LinkService linkService;

    @ApiOperation("发布友链")
    @PostMapping(path = "",produces = "application/json")
    public ResModel issue(@RequestBody Link link){
        return linkService.issue(link);
    }

    @ApiOperation("查询友链")
    @GetMapping
    public ResModel<List<Link>> list(){
        return linkService.getList();
    }

    @ApiOperation("分页查询友链")
    @GetMapping("/{current}/{size}")
    public ResModel<IPage<Link>> list(@PathVariable Integer current, @PathVariable Integer size){
        return linkService.getByPage(current,size);
    }

    @ApiOperation("查询自己友链")
    @GetMapping("/{uid}")
    public ResModel<List<Link>> listByUid(@PathVariable Integer uid){
        return linkService.listByUid(uid);
    }

    @ApiOperation("删除友链")
    @DeleteMapping("/{id}")
    public ResModel delMsg(@PathVariable Integer id){
        return linkService.delLink(id);
    }
}
